<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="模板">
        <el-tag type="info">Excel模板</el-tag>
        <el-tag>
          <i class="el-icon-download" />
          <a :href="BASE_OSS + '/excel/Subject.xlsx'" target="_blank">下载</a>
        </el-tag>
      </el-form-item>
      <el-form-item label="上传">
        <el-upload
          ref="upload"
          :action="importUrl"
          :on-success="uploadSuccess"
          :show-file-list="true"
          :auto-upload="false"
        >
          <el-button slot="trigger" size="small" type="primary"
            >选择文件</el-button
          >
          <el-button
            style="margin-left: 10px"
            size="small"
            type="success"
            @click="submitUpload"
            >上传到服务器</el-button
          >
          <div slot="tip" class="el-upload__tip">只能上传xlsx文件</div>
        </el-upload>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import subject from "@/api/edu/subject";

export default {
  data() {
    return {
      // BASE_OSS: process.env.BASE_OSS,
      BASE_OSS: "https://99edu.oss-cn-beijing.aliyuncs.com",
      importUrl: process.env.VUE_APP_BASE_API + "/service_edu/subject/import",
    };
  },
  methods: {
    uploadSuccess(res, file, fileList) {
      this.$refs.upload.clearFiles();
      if (res.code !== 20000) {
        this.$message.error(res.message);
      } else {
        this.$message.success("上传成功");
      }
    },
    submitUpload() {
      this.$refs.upload.submit();
    },
  },
};
</script>